﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using SF.DBUtility;
using SF.Common;//Please add references
namespace SF.DAL
{
	/// <summary>
	/// 数据访问类:sf_goods_info
	/// </summary>
	public partial class sf_goods_info
	{
		public sf_goods_info()
		{}
		#region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from sf_goods_info");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.BigInt)
			};
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string goodsNum,string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from sf_goods_info");
            strSql.Append(" where goodsNum=@goodsNum");
            if (where!="")
            {
                strSql.Append(" and "+where);
            }
            SqlParameter[] parameters = {
					new SqlParameter("@goodsNum", SqlDbType.NVarChar)
			};
            parameters[0].Value = goodsNum;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public long Add(SF.Model.sf_goods_info model)
		{
            int newID = 0;
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into sf_goods_info(");
                        strSql.Append("busnieseNum,appNum,templatesNum,goodsNum,typeNum,names,brandName,place,unit,validTime,suitPerson,remark,times,num,costPrice,showPrice,salesPrice,sort,showImgs,status,ishot,goodsTypeNum)");
                        strSql.Append(" values (");
                        strSql.Append("@busnieseNum,@appNum,@templatesNum,@goodsNum,@typeNum,@names,@brandName,@place,@unit,@validTime,@suitPerson,@remark,@times,@num,@costPrice,@showPrice,@salesPrice,@sort,@showImgs,@status,@ishot,@goodsTypeNum)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters = {
					new SqlParameter("@busnieseNum", SqlDbType.NVarChar,50),
					new SqlParameter("@appNum", SqlDbType.NVarChar,50),
					new SqlParameter("@templatesNum", SqlDbType.NVarChar,50),
					new SqlParameter("@goodsNum", SqlDbType.NVarChar,50),
					new SqlParameter("@typeNum", SqlDbType.NVarChar,50),
					new SqlParameter("@names", SqlDbType.NVarChar,50),
					new SqlParameter("@brandName", SqlDbType.NVarChar,50),
					new SqlParameter("@place", SqlDbType.NVarChar,100),
					new SqlParameter("@unit", SqlDbType.NVarChar,10),
					new SqlParameter("@validTime", SqlDbType.NVarChar,50),
					new SqlParameter("@suitPerson", SqlDbType.NVarChar,50),
					new SqlParameter("@remark", SqlDbType.NVarChar,-1),
					new SqlParameter("@times", SqlDbType.NVarChar,20),
					new SqlParameter("@num", SqlDbType.Int,4),
					new SqlParameter("@costPrice", SqlDbType.Decimal,9),
					new SqlParameter("@showPrice", SqlDbType.Decimal,9),
					new SqlParameter("@salesPrice", SqlDbType.Decimal,9),
					new SqlParameter("@sort", SqlDbType.Int,4),
					new SqlParameter("@showImgs", SqlDbType.NVarChar,50),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@ishot", SqlDbType.Int,4),
					new SqlParameter("@goodsTypeNum", SqlDbType.NVarChar,20)};
                        parameters[0].Value = model.busnieseNum;
                        parameters[1].Value = model.appNum;
                        parameters[2].Value = model.templatesNum;
                        parameters[3].Value = model.goodsNum;
                        parameters[4].Value = model.typeNum;
                        parameters[5].Value = model.names;
                        parameters[6].Value = model.brandName;
                        parameters[7].Value = model.place;
                        parameters[8].Value = model.unit;
                        parameters[9].Value = model.validTime;
                        parameters[10].Value = model.suitPerson;
                        parameters[11].Value = model.remark;
                        parameters[12].Value = model.times;
                        parameters[13].Value = model.num;
                        parameters[14].Value = model.costPrice;
                        parameters[15].Value = model.showPrice;
                        parameters[16].Value = model.salesPrice;
                        parameters[17].Value = model.sort;
                        parameters[18].Value = model.showImgs;
                        parameters[19].Value = model.status;
                        parameters[20].Value = model.ishot;
                        parameters[21].Value = model.goodsTypeNum;

                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters);
                        newID = int.Parse(obj.ToString());

                        #region sf_goods_Img upload
                        if (model.goodsImgs != null)
                        {
                            foreach (Model.sf_goods_img temp in model.goodsImgs)
                            {
                                StringBuilder strSql2 = new StringBuilder();
                                strSql2.Append("insert into sf_goods_img(");
                                strSql2.Append("busnieseNum,appNum,templatesNum,goodsNum,imgName,imgUri)");
                                strSql2.Append(" values (");
                                strSql2.Append("@busnieseNum,@appNum,@templatesNum,@goodsNum,@imgName,@imgUri)");
                                SqlParameter[] imgPar = {
                                                new SqlParameter("@busnieseNum", SqlDbType.NVarChar,50),
                                                new SqlParameter("@appNum", SqlDbType.NVarChar,50),
                                                new SqlParameter("@templatesNum", SqlDbType.NVarChar,50),
					                            new SqlParameter("@goodsNum", SqlDbType.NVarChar,50),
					                            new SqlParameter("@imgName", SqlDbType.NVarChar,200),
                                                new SqlParameter("@imgUri", SqlDbType.NVarChar,200)};

                                imgPar[0].Value = temp.busnieseNum;
                                imgPar[1].Value = temp.appNum;
                                imgPar[2].Value = temp.templatesNum;
                                imgPar[3].Value = temp.goodsNum;
                                imgPar[4].Value = temp.imgName;
                                imgPar[5].Value = temp.imgUri;

                                DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), imgPar);

                                strSql2.Length = 0;
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return 0;
                    }
                }
            }

            return newID; 
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(SF.Model.sf_goods_info model)
		{
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
			            StringBuilder strSql=new StringBuilder();
			            strSql.Append("update sf_goods_info set ");
			            strSql.Append("busnieseNum=@busnieseNum,");
			            strSql.Append("appNum=@appNum,");
			            strSql.Append("templatesNum=@templatesNum,");
			            strSql.Append("goodsNum=@goodsNum,");
			            strSql.Append("typeNum=@typeNum,");
			            strSql.Append("names=@names,");
			            strSql.Append("brandName=@brandName,");
			            strSql.Append("place=@place,");
			            strSql.Append("unit=@unit,");
			            strSql.Append("validTime=@validTime,");
			            strSql.Append("suitPerson=@suitPerson,");
			            strSql.Append("remark=@remark,");
			            strSql.Append("times=@times,");
			            strSql.Append("num=@num,");
			            strSql.Append("costPrice=@costPrice,");
			            strSql.Append("showPrice=@showPrice,");
			            strSql.Append("salesPrice=@salesPrice,");
			            strSql.Append("sort=@sort,");
			            strSql.Append("showImgs=@showImgs,");
			            strSql.Append("status=@status,");
			            strSql.Append("ishot=@ishot,");
			            strSql.Append("goodsTypeNum=@goodsTypeNum");
			            strSql.Append(" where id=@id");
			            SqlParameter[] parameters = {
					            new SqlParameter("@busnieseNum", SqlDbType.NVarChar,50),
					            new SqlParameter("@appNum", SqlDbType.NVarChar,50),
					            new SqlParameter("@templatesNum", SqlDbType.NVarChar,50),
					            new SqlParameter("@goodsNum", SqlDbType.NVarChar,50),
					            new SqlParameter("@typeNum", SqlDbType.NVarChar,50),
					            new SqlParameter("@names", SqlDbType.NVarChar,50),
					            new SqlParameter("@brandName", SqlDbType.NVarChar,50),
					            new SqlParameter("@place", SqlDbType.NVarChar,100),
					            new SqlParameter("@unit", SqlDbType.NVarChar,10),
					            new SqlParameter("@validTime", SqlDbType.NVarChar,50),
					            new SqlParameter("@suitPerson", SqlDbType.NVarChar,50),
					            new SqlParameter("@remark", SqlDbType.NVarChar,-1),
					            new SqlParameter("@times", SqlDbType.NVarChar,20),
					            new SqlParameter("@num", SqlDbType.Int,4),
					            new SqlParameter("@costPrice", SqlDbType.Decimal,9),
					            new SqlParameter("@showPrice", SqlDbType.Decimal,9),
					            new SqlParameter("@salesPrice", SqlDbType.Decimal,9),
					            new SqlParameter("@sort", SqlDbType.Int,4),
					            new SqlParameter("@showImgs", SqlDbType.NVarChar,50),
					            new SqlParameter("@status", SqlDbType.Int,4),
					            new SqlParameter("@ishot", SqlDbType.Int,4),
					            new SqlParameter("@goodsTypeNum", SqlDbType.NVarChar,20),
					            new SqlParameter("@id", SqlDbType.BigInt,8)};
			            parameters[0].Value = model.busnieseNum;
			            parameters[1].Value = model.appNum;
			            parameters[2].Value = model.templatesNum;
			            parameters[3].Value = model.goodsNum;
			            parameters[4].Value = model.typeNum;
			            parameters[5].Value = model.names;
			            parameters[6].Value = model.brandName;
			            parameters[7].Value = model.place;
			            parameters[8].Value = model.unit;
			            parameters[9].Value = model.validTime;
			            parameters[10].Value = model.suitPerson;
			            parameters[11].Value = model.remark;
			            parameters[12].Value = model.times;
			            parameters[13].Value = model.num;
			            parameters[14].Value = model.costPrice;
			            parameters[15].Value = model.showPrice;
			            parameters[16].Value = model.salesPrice;
			            parameters[17].Value = model.sort;
			            parameters[18].Value = model.showImgs;
			            parameters[19].Value = model.status;
			            parameters[20].Value = model.ishot;
			            parameters[21].Value = model.goodsTypeNum;
			            parameters[22].Value = model.id;

			            int rows=DbHelperSQL.ExecuteSql(conn,trans,strSql.ToString(),parameters);

                        #region sf_goods_Img upload

                        //删除已删除的图片
                        string where = " busnieseNum='" +model.busnieseNum+"' and appNum = '"+model.appNum+"' and  templatesNum = '"+model.templatesNum+"' ";
                        new sf_goods_img().DeleteList(conn, trans, model.goodsImgs, model.goodsNum,where);

                        if (model.goodsImgs != null)
                        {
                            foreach (Model.sf_goods_img temp in model.goodsImgs)
                            {
                                StringBuilder strSql2 = new StringBuilder();
                                if (temp.id > 0)
                                {
                                    strSql2.Append("update sf_goods_img set ");                                    
                                    strSql2.Append("goodsNum=@goodsNum,");
                                    strSql2.Append("imgName=@imgName,");
                                    strSql2.Append("imgUri=@imgUri");
                                    strSql2.Append(" where id=@id ");
                                    SqlParameter[] imgPar = {
					                            new SqlParameter("@goodsNum", SqlDbType.NVarChar,50),
					                            new SqlParameter("@imgName", SqlDbType.NVarChar,200),
                                                new SqlParameter("@imgUri", SqlDbType.NVarChar,200),
					                            new SqlParameter("@id", SqlDbType.Int,4)};

                                    imgPar[0].Value = temp.goodsNum;
                                    imgPar[1].Value = temp.imgName;
                                    imgPar[2].Value = temp.imgUri;
                                    imgPar[3].Value = temp.id;

                                    DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), imgPar);
                                    strSql2.Length = 0;
                                }
                                else
                                {
                                    strSql2.Append("insert into sf_goods_img(");
                                    strSql2.Append("busnieseNum,appNum,templatesNum,goodsNum,imgName,imgUri)");
                                    strSql2.Append(" values (");
                                    strSql2.Append("@busnieseNum,@appNum,@templatesNum,@goodsNum,@imgName,@imgUri)");
                                    SqlParameter[] imgPar = {
                                                new SqlParameter("@busnieseNum", SqlDbType.NVarChar,50),
                                                new SqlParameter("@appNum", SqlDbType.NVarChar,50),
                                                new SqlParameter("@templatesNum", SqlDbType.NVarChar,50),
					                            new SqlParameter("@goodsNum", SqlDbType.NVarChar,50),
					                            new SqlParameter("@imgName", SqlDbType.NVarChar,200),
                                                new SqlParameter("@imgUri", SqlDbType.NVarChar,200)};

                                    imgPar[0].Value = temp.busnieseNum;
                                    imgPar[1].Value = temp.appNum;
                                    imgPar[2].Value = temp.templatesNum;
                                    imgPar[3].Value = temp.goodsNum;
                                    imgPar[4].Value = temp.imgName;
                                    imgPar[5].Value = temp.imgUri;

                                    DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), imgPar);

                                    strSql2.Length = 0;
                                }
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return false;
                    }
                }
            }

            return true;
        }

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from sf_goods_info ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.BigInt)
			};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from sf_goods_info ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SF.Model.sf_goods_info GetModel(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,busnieseNum,appNum,templatesNum,goodsNum,typeNum,names,brandName,place,unit,validTime,suitPerson,remark,times,num,costPrice,showPrice,salesPrice,sort,showImgs,status,ishot,goodsTypeNum from sf_goods_info ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.BigInt)
			};
			parameters[0].Value = id;

			SF.Model.sf_goods_info model=new SF.Model.sf_goods_info();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SF.Model.sf_goods_info GetModel(string where)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,busnieseNum,appNum,templatesNum,goodsNum,typeNum,names,brandName,place,unit,validTime,suitPerson,remark,times,num,costPrice,showPrice,salesPrice,sort,showImgs,status,ishot,goodsTypeNum from sf_goods_info ");
            if (where!="")
            {
                strSql.Append(" where " + where);
            }
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SF.Model.sf_goods_info DataRowToModel(DataRow row)
		{
			SF.Model.sf_goods_info model=new SF.Model.sf_goods_info();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["busnieseNum"]!=null)
				{
					model.busnieseNum=row["busnieseNum"].ToString();
				}
				if(row["appNum"]!=null)
				{
					model.appNum=row["appNum"].ToString();
				}
				if(row["templatesNum"]!=null)
				{
					model.templatesNum=row["templatesNum"].ToString();
				}
				if(row["goodsNum"]!=null)
				{
					model.goodsNum=row["goodsNum"].ToString();
				}
				if(row["typeNum"]!=null)
				{
					model.typeNum=row["typeNum"].ToString();
				}
				if(row["names"]!=null)
				{
					model.names=row["names"].ToString();
				}
				if(row["brandName"]!=null)
				{
					model.brandName=row["brandName"].ToString();
				}
				if(row["place"]!=null)
				{
					model.place=row["place"].ToString();
				}
				if(row["unit"]!=null)
				{
					model.unit=row["unit"].ToString();
				}
				if(row["validTime"]!=null)
				{
					model.validTime=row["validTime"].ToString();
				}
				if(row["suitPerson"]!=null)
				{
					model.suitPerson=row["suitPerson"].ToString();
				}
				if(row["remark"]!=null)
				{
					model.remark=row["remark"].ToString();
				}
				if(row["times"]!=null)
				{
					model.times=row["times"].ToString();
				}
				if(row["num"]!=null && row["num"].ToString()!="")
				{
					model.num=int.Parse(row["num"].ToString());
				}
				if(row["costPrice"]!=null && row["costPrice"].ToString()!="")
				{
					model.costPrice=decimal.Parse(row["costPrice"].ToString());
				}
				if(row["showPrice"]!=null && row["showPrice"].ToString()!="")
				{
					model.showPrice=decimal.Parse(row["showPrice"].ToString());
				}
				if(row["salesPrice"]!=null && row["salesPrice"].ToString()!="")
				{
					model.salesPrice=decimal.Parse(row["salesPrice"].ToString());
				}
				if(row["sort"]!=null && row["sort"].ToString()!="")
				{
					model.sort=int.Parse(row["sort"].ToString());
				}
				if(row["showImgs"]!=null)
				{
					model.showImgs=row["showImgs"].ToString();
				}
				if(row["status"]!=null && row["status"].ToString()!="")
				{
					model.status=int.Parse(row["status"].ToString());
				}
				if(row["ishot"]!=null && row["ishot"].ToString()!="")
				{
					model.ishot=int.Parse(row["ishot"].ToString());
				}
				if(row["goodsTypeNum"]!=null)
				{
					model.goodsTypeNum=row["goodsTypeNum"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,busnieseNum,appNum,templatesNum,goodsNum,typeNum,names,brandName,place,unit,validTime,suitPerson,remark,times,num,costPrice,showPrice,salesPrice,sort,showImgs,status,ishot,goodsTypeNum ");
			strSql.Append(" FROM sf_goods_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,busnieseNum,appNum,templatesNum,goodsNum,typeNum,names,brandName,place,unit,validTime,suitPerson,remark,times,num,costPrice,showPrice,salesPrice,sort,showImgs,status,ishot,goodsTypeNum ");
			strSql.Append(" FROM sf_goods_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM sf_goods_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from sf_goods_info T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "sf_goods_info";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(long id, string strValue)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update sf_goods_info set " + strValue);
                strSql.Append(" where id=" + id);
                DbHelperSQL.ExecuteSql(strSql.ToString());
                return true;
            }
            catch (Exception)
            {
            }
            return false;
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public DataSet GetList(int isOnShelf, string category_id, int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM sf_goods_info where 1=1 ");
            strSql.Append(" and status = " + (isOnShelf > 0 ? isOnShelf : 1));
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and  " + strWhere);
            }
            if (!String.IsNullOrEmpty(category_id.Trim()))
            {
                DAL.sf_goods_types types = new DAL.sf_goods_types();
                DataTable dt = types.GetList("class_list like '%"+ types.GetModel(category_id,"").class_list +"%'").Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        strSql.Append(" and  typeNum='" + dt.Rows[i]["typeNum"] + "' ");
                    }
                    else
                    {
                        strSql.Append(" or  typeNum='" + dt.Rows[i]["typeNum"] + "' ");
                    }
                }
            }
            recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
            return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(string strValue, string where)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update sf_goods_info set " + strValue);
                strSql.Append(" where " + where);
                DbHelperSQL.ExecuteSql(strSql.ToString());
                return true;
            }
            catch (Exception)
            {
            }
            return false;
        }
		#endregion  ExtensionMethod
	}
}

